package cc.linker.steplink.crm.task;


import cc.linker.steplink.crm.commons.lock.RedisLock;
import cc.linker.steplink.crm.merchant.service.PublicMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.TimeUnit;


/**
 * 自定义菜单保推送任务
 */


@Slf4j
@Component
public class PublicMenuTask {


    @Autowired
    private PublicMenuService publicMenuService;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RedisLock("PublicMenuTokens")
    @Scheduled(cron = "0 0/30 * * * ?")
    public void publicMenuTokens(){

        List<String> tokens = publicMenuService.getPublicMenuTokens();
        for(String token:tokens){
            String key = "publicMenuToken_"+token;
            stringRedisTemplate.opsForValue().set(key,"1",31, TimeUnit.MINUTES);
        }
    }

}
